﻿using System.Collections.Generic;
using CodeParser.Tokens;

namespace CodeParser.Expressions
{
    public class DocumentParser
        : ExpressionParser
    {

        public DocumentParser()
        {
            Parsers = new List<ExpressionParser>();
        }

        public override Expression Parse(Token[] tokens, int index)
        {
            var effect = new Document
                             {
                                 TokenLength = tokens.Length,
                                 Content = ParseSubExpression(tokens, 0, null, Parsers),
                                 StringIndex = tokens[index].Index,
                                 StringLength = tokens[tokens.Length - 1].Index + tokens[tokens.Length - 1].Value.Length
                             };
            effect.Add(effect.Content);

            var lastToken = tokens[index + effect.TokenLength - 1];
            effect.StringLength = lastToken.Index + lastToken.Value.Length - effect.StringIndex;

            return effect;
        }

        public List<ExpressionParser> Parsers { get; set; }

    }
}